<template>
  <a-spin :spinning="confirmLoading">
    <a-table ref="table" size="middle" :scroll="{x:true}" bordered rowKey="id" :columns="columns"
      :dataSource="dataSource" :loading="loading" class="j-table-force-nowrap">
      <template slot="paramValue" slot-scope="text,record">
          <a-input v-model="record.paramValue" @blur="changeParam(record)"/>
        </template>
    </a-table>
  </a-spin>
</template>

<script>

import { httpAction, getAction, postAction } from '@/api/manage'

export default {
  name: 'CollectSourceParamForm',
  components: {
  },
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      /* table加载状态 */
      loading: false,
      dataSource: [],
      confirmLoading: false,
      recordId: '',
      model: {
      },
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '参数',
          align: "center",
          dataIndex: 'paramName'
        },
        {
          title: '值',
          align: "center",
          dataIndex: 'paramValue',
          scopedSlots: { customRender: 'paramValue' }

        },
      ],
      url: {
        getconfig: "/dcloud-platform/api/collectSourceParam/v1/getListBySourceId",
        changeParams: "/dcloud-platform/api/collectSourceParam/v1/changeParam",
        queryById: "/dcloud-platform/api/collectSourceParam//v1/queryById"
      }
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  methods: {
    showConfig(record) {

      //this.model = Object.assign({}, record); 拷贝
      let sourceId = record.tid;
      this.recordId = record.tid;  //打开弹出层，将主键记录下来
      let params={sourceId}
      //获取该数据源的所有配置信息
      postAction(this.url.getconfig, params).then(res => {
        if (res.success) {
              console.log(res)
              this.dataSource = res.result.records || res.result
            } else {
              this.$message.warning(res.message)
            }
      })
      this.visible = true;
    },

    changeParam(record){
      postAction(this.url.changeParams, record).then(res => {
        if (res.success) {
              // this.$message.info("修改参数配置成功")
            } else {
              this.$message.warning(res.message)
            }
      })
    },

  }
}
</script>